var e = require, t = module, n = exports;

Object.defineProperty(n, "__esModule", {
    value: !0
});

var o = e("Global"), i = e("PlayerModel"), a = e("ArmView"), r = e("AudioManager"), s = e("FireView"), c = e("GameData"), l = e("PlayerMain"), d = e("LoadManager"), u = function() {
    function e() {}
    return e.getInstance = function() {
        return this._manager || (this._manager = new e()), this._manager;
    }, e.prototype.loadGun = function() {
        return new Promise(function(e, o) {
            o();
        });
    }, e.prototype.loadSkin = function(i) {
        return new Promise(function(n, t) {
            d.default.getInstance().loadRes({
                url: "skeleton/机甲动画输出/skeleton",
                type: sp.SkeletonData
            }).then(function(e) {
                i.skeleton && e instanceof sp.SkeletonData && (i.skeleton.skeletonData = e, i.skeleton.premultipliedAlpha = false, i.changeAnimation({
                    animation: "animation2",
                    loop: !0
                }), i.hpView.node.y = 130, i.model.personIdx < -15 || i.model.personIdx < 100 && 16 < i.model.personIdx ? i.skeleton.setAttachment("tou_1", "toukui") : 100 <= i.model.personIdx ? i.skeleton.setAttachment("tou_1", "tou_e" + (i.model.personIdx - 100)) : i.model.personIdx < 0 ? i.skeleton.setAttachment("tou_1", "tou_e" + o.G.getEggIdx(i.model.personIdx, 2)) : i.skeleton.setAttachment("tou_1", "tou_" + i.model.personIdx)), 
                n();
            }).catch(function(e) {
                console.error(e), t();
            });
        });
    }, e.prototype.doAttack = function(e) {
		console.log("发射子弹---------------------------"+e)
        if (e.isFill) return !0;
        if (e.machineModel.changeModel(), c.GD.isEffect) switch (e.machineModel.fire) {
          case i.FireType.手枪:
            r.default.getInstance().playAudio("手枪", .3);
            break;

          case i.FireType.冲锋枪:
            r.default.getInstance().playAudio("冲锋枪", 1);
            break;

          case i.FireType.暴力枪:
          case i.FireType.狙击枪:
            r.default.getInstance().playAudio("狙击枪", 1);
            break;

          case i.FireType.加特林:
            r.default.getInstance().playAudio("加特林", 1);
            break;

          case i.FireType.闪电枪:
            r.default.getInstance().playAudio("闪电枪", .3);
            break;

          case i.FireType.科技枪:
            r.default.getInstance().playAudio("科技枪", .3);
            break;

          case i.FireType.激光枪:
            r.default.getInstance().playAudio("激光枪");
            break;

          case i.FireType.落冰枪:
            r.default.getInstance().playAudio("手枪", .3);
            break;

          case i.FireType.彩蛋枪:
            r.default.getInstance().playAudio("冲锋枪", 1);
            break;

          default:
            r.default.getInstance().playAudio("狙击枪", 1);
        }
        for (var o = e.machineModel.getCount(), n = 0; n < o; n++) {
            var t = e.gameView.getArm().getComponent(a.default);
            t && (t.node.setParent(e.gameView.bulletLayout), t.node.setPosition(e.node.getPosition().add(e.getOffect())), 
            t.init(e, e.machineModel, e.getDir(), e.node.getPosition().add(e.getOffect())), 
            e.offect = e.getDir().mul(2 * -e.machineModel.pow));
        }
        return this.addFire(e), 0 < e.machineModel.IDLE && (e.isIdle || (e.isIdle = !0, 
        e.scheduleOnce(function() {
            e.isIdle = !1;
        }, e.machineModel.IDLE))), 0 < e.machineModel.time && e.machineModel.addCount(o) && (e.isFill = !0, 
        e.fillView && e.fillView.init(e.machineModel.time), e.scheduleOnce(function() {
            e.isFill = !1, e.machineModel.clearCount();
        }, e.machineModel.time)), !0;
    }, e.prototype.addFire = function(e) {
        e.fire || (e.fire = e.gameView.getFire().getComponent(s.default), e.fire.node.setParent(e.node), 
        e.updateFire(), e.fire.init(e.machineModel)), e.fire.doFire();
    }, e.prototype.doHurt = function(e, o, n) {
        e.canHurt() && (e.checkHurt(o, n, e.machineModel), e.machineModel.isDead() ? this.die(e) : (e.canMove() && n && (e.offect = n.mul(10 * o.pow)), 
        e.isHurt || (e.isHurt = !0, cc.tween(e.skeleton.node).repeat(2, cc.tween().call(function() {
            e.skeleton.node.color = cc.Color.RED;
        }).delay(.08).call(function() {
            e.skeleton.node.color = cc.Color.WHITE;
        }).delay(.08)).call(function() {
            e.isHurt = !1;
        }).start()), o.type == i.ArmType.闪电枪 ? e.doEle(function() {
            e.model.hasBuffer(i.BufferType.变身) || e.loadSkin(e.model.personIdx).then(function() {
                e.skeleton && e.skeleton.node.setPosition(cc.v2(0, -20));
            });
        }) : o.type == i.ArmType.冰冻枪 ? e.doIce() : o.type == i.ArmType.切割 && e.doCut()));
    }, e.prototype.die = function(n) {
        n.model.addBuffer(i.BufferType.变身), n.model.addBuffer(i.BufferType.无敌), n.pauseMove(!0), 
        n.skeleton && n.skeleton.node.setPosition(cc.v2(0, -20)), n.gameView.appendSkeleton({
            url: "skeleton/机甲动画输出/skeleton",
            root: n.gameView.layout,
            pos: n.node.getPosition()
        }).then(function(o) {
            o instanceof sp.Skeleton ? (n.modelType = l.ModelType.DEFAULT, n.loadSkin(n.model.personIdx).then(function() {
                n.changeGun(n.model.gunIdx), n.hpView.init(n.model.MAX_HP), n.hpView.refresh(n.model.HP);
            }), o.node.scaleX = n.skeleton.node.scaleX, o.node.scaleY = n.skeleton.node.scaleY, 
            o.node.zIndex = n.node.zIndex - 1, o.setAnimation(0, "animation3", !1), o.schedule(function() {
                var e = o.findBone("juese_root");
                e && (e = n.gameView.layout.convertToNodeSpaceAR(o.node.convertToWorldSpaceAR(cc.v2(.5 * e.worldX, .5 * e.worldY))), 
                n.node.setPosition(e));
            }, .016), o.setCompleteListener(function() {
                o.setCompleteListener(null), o.unscheduleAllCallbacks(), n.model.removeBuffer(i.BufferType.变身), 
                n.model.removeBuffer(i.BufferType.无敌), n.gameView.removeSkeleton(o.node);
            })) : (n.skeleton.setAnimation(0, "animation3", !1), n.skeleton.setCompleteListener(function() {
                n.skeleton.setCompleteListener(null), n.modelType = l.ModelType.DEFAULT, n.loadSkin().then(function() {
                    n.model.removeBuffer(i.BufferType.变身), n.model.removeBuffer(i.BufferType.无敌), n.resumeMove(!0), 
                    n.sprite && n.canShowGun() && (n.sprite.node.opacity = 255), n.hpView.init(n.model.MAX_HP), 
                    n.hpView.refresh(n.model.HP);
                });
            }));
        });
    }, e.prototype.getOffect = function(e, o, n) {
        if (void 0 === o && (o = 0), void 0 === n && (n = 0), e.skeleton) {
            if (1 == e.machineModel.idx) {
                var t = e.skeleton.findBone("wuqi_you");
                return this.getFireOffect(e, t);
            }
            t = e.skeleton.findBone("wuqi_zuo");
            return this.getFireOffect(e, t);
        }
        return cc.Vec2.ZERO;
    }, e.prototype.getFireOffect = function(e, o, n, t) {
        return void 0 === n && (n = 0), void 0 === t && (t = 0), o ? cc.v2(o.worldX * e.skeleton.node.scaleX, o.worldY * e.skeleton.node.scaleY + e.skeleton.node.y) : cc.Vec2.ZERO;
    }, e.prototype.updateDir = function(e, o) {
        var n;
        e.skeleton && (0 < o.x ? e.skeleton.node.scaleX = -.5 : o.x < 0 && (e.skeleton.node.scaleX = .5), 
        (n = e.skeleton.findSlot("you_shou")) && n.bone && (0 < e.skeleton.node.scaleX ? n.bone.rotation = 180 + cc.misc.radiansToDegrees(Math.atan2(o.y, o.x)) : n.bone.rotation = -cc.misc.radiansToDegrees(Math.atan2(o.y, o.x))), 
        (n = e.skeleton.findSlot("zuo_shou")) && n.bone && (0 < e.skeleton.node.scaleX ? n.bone.rotation = 180 + cc.misc.radiansToDegrees(Math.atan2(o.y, o.x)) : n.bone.rotation = -cc.misc.radiansToDegrees(Math.atan2(o.y, o.x))));
    }, e._manager = null, e;
}();

n.default = u;